package org.agony2d.display.core {
	import org.agony2d.core.agony_internal;
	
	use namespace agony_internal;
	
public class UUManager {
	
	agony_internal static function startup( autoFit:Boolean ) : void {
		
	}
	
	agony_internal static function addModule( moduleName:String, stateType:Class ) : ModuleUU {
		
	}
	
	agony_internal static function getModule( moduleName:String ) : ModuleUU {
		return m_moduleList[moduleName]
	}
	
	
	agony_internal static function exitAllModules( exceptModuleNames:Array = null ) : void {
		var key:*
		var module:ModuleUU
		
		//for (key in m_moduleList) {
			//if (!(exceptModuleNames && exceptModuleNames.indexOf(key) != -1)) {
				//module = m_moduleList[key]
				//if (module.m_stateFusion) {
					//module.exit()
				//}
			//}
		//}
	}
	
	
	//////////////////////////////////
	//////////////////////////////////
	// double press
	//////////////////////////////////
	//////////////////////////////////
	agony_internal static function addDoublePressEvent( target:IComponent, listener:Function, priority:int = 0 ) : void {
		if (!m_doublePressMap[target]) {
			m_doublePressMap[target] = -1
			target.addEventListener(AEvent.PRESS, ____onCheckDoublePress, -8000)
		}
		target.addEventListener(AEvent.DOUBLE_PRESS, listener, priority)
	}
	
	agony_internal static function removeDoublePressEvent( target:IComponent, listener:Function ) : void {
		var delayID:int
		
		target.removeEventListener(AEvent.DOUBLE_PRESS, listener)
		if (!target.hasEventListener(AEvent.DOUBLE_PRESS)) {
			target.removeEventListener(AEvent.PRESS, ____onCheckDoublePress)
			delayID = m_doublePressMap[target]
			if (delayID >= 0) {
				DelayManager.getInstance().removeDelayedCall(delayID)
			}
			delete m_doublePressMap[target]
		}
	}
	
	agony_internal static function removeAllDoublePressEvent( target:IComponent ) : void {
		var delayID:int
		
		if (m_doublePressMap[target]) {
			target.removeEventAllListeners(AEvent.DOUBLE_PRESS)
			target.removeEventListener(AEvent.PRESS, ____onCheckDoublePress)
			delayID = m_doublePressMap[target]
			if (delayID >= 0) {
				DelayManager.getInstance().removeDelayedCall(delayID)
			}
			delete m_doublePressMap[target]
		}
	}
	
	agony_internal static function ____onCheckDoublePress( e:AEvent ) : void {
		var target:ComponentProxy
		var delayID:int
		
		target = e.target as ComponentProxy
		delayID = m_doublePressMap[target]
		if (delayID == -1) {
			m_doublePressMap[target] = DelayManager.getInstance().delayedCall(m_doubliePressInterval, doDoublePressInvalid, target)
		}
		else {
			DelayManager.getInstance().removeDelayedCall(delayID)
			m_doublePressMap[target] = -1
			target.view.m_notifier.dispatchDirectEvent(AEvent.DOUBLE_PRESS)
		}
	}
	
	agony_internal static function doDoublePressInvalid( target:IComponent ) : void {
		m_doublePressMap[target] = -1
		//trace("dodoublePressInvalid")
	}
	
}
}